/*
 * @Author: xiaoliang
 * @Date: 2025-03-05 14:47:56
 * @LastEditors: xiaoliang
 * @LastEditTime: 2025-03-05 14:47:57
 * @FilePath: /codepiece/debounce.js
 * @Description: 防抖
 */

function debounce(func, wait) {
  let timeout;
  return function() {
    const context = this;
    const args = arguments;
    clearTimeout(timeout);
    timeout = setTimeout(() => {
      func.apply(context, args);
    }, wait);
  };
}

// 使用示例
window.addEventListener('resize', debounce(function() {
  console.log('窗口大小改变了！');
}, 250));